package com.javacrafting.mifos.web;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import com.javacrafting.mifos.domain.Product;
import com.javacrafting.mifos.service.LoanProductService;

/**
 *
 */
public class ViewLoanProductsController implements Controller
{
	private final LoanProductService loanProductService;
	
	public ViewLoanProductsController(final LoanProductService loanProductService)
	{
		this.loanProductService = loanProductService;
	}
	
	public ModelAndView handleRequest(HttpServletRequest req, HttpServletResponse res) throws Exception {
		
		List<Product> loanProducts = loanProductService.findAllLoanProducts();
		
		final Map<String, Object> myModel = new HashMap<String, Object>();
        myModel.put("loanProducts", loanProducts);
        
        return new ModelAndView("viewloanproducts", "model", myModel);
	}

}